Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Externalised destination table cache expiry duration for BigQuery Connector #8283

Merged
merged 2 commits into from
Jun 29, 2021
Merged

Externalised destination table cache expiry duration for BigQuery Connector #8283

merged 2 commits into from
Jun 29, 2021

Conversation

ayushbilala
Copy link
Contributor

Resolves #8236

Made destination table cache expiry duration configurable. This can be configured using bigquery.destination-table-cache-expiry property. Defaults to 15m.

@cla-bot cla-bot bot added the cla-signed label Jun 15, 2021
@@ -78,6 +80,10 @@
.expireAfterWrite(caseInsensitiveNameMatchingCacheTtl.toMillis(), MILLISECONDS);
this.remoteDatasets = remoteNamesCacheBuilder.build();
this.remoteTables = remoteNamesCacheBuilder.build();
this.destinationTableCache = CacheBuilder.newBuilder()
.expireAfterWrite(config.getDestinationTableCacheExpiry().roundTo(TimeUnit.MINUTES), TimeUnit.MINUTES)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expireAfterWrite(config.getDestinationTableCacheExpiry().toMillis(), MILLISECONDS)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

return destinationTableCacheExpiry;
}

@Config("bigquery.destination-table-cache-expiry")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe bigquery.views-cache-ttl would be a better name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}

@Config("bigquery.destination-table-cache-expiry")
@ConfigDescription("Duration for which query and destination table will be cached")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duration for which the results of querying a view will be cached

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -47,6 +48,7 @@
private int maxReadRowsRetries = DEFAULT_MAX_READ_ROWS_RETRIES;
private boolean caseInsensitiveNameMatching;
private Duration caseInsensitiveNameMatchingCacheTtl = new Duration(1, MINUTES);
private Duration destinationTableCacheExpiry = new Duration(15, TimeUnit.MINUTES);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe viewsCacheTtl

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -130,7 +122,7 @@ private TableInfo getActualTable(
String query = bigQueryClient.selectSql(table.getTableId(), requiredColumns);
log.debug("query is %s", query);
try {
return destinationTableCache.get(query, new DestinationTableBuilder(bigQueryClient, config, query, table.getTableId()));
return bigQueryClient.getDestinationTableCache().get(query, new DestinationTableBuilder(bigQueryClient, config, query, table.getTableId()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could move DestinationTableBuilder to BigQueryClient and expose a method bigQueryClient.getCachedTable(config, table.getTableId(), requiredColumns) instead of exposing the cache directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -129,76 +109,12 @@ private TableInfo getActualTable(
// get it from the view
String query = bigQueryClient.selectSql(table.getTableId(), requiredColumns);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move this into bigQueryClient.getCachedTable as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member

@hashhar hashhar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me % comments.

@@ -337,4 +362,63 @@ public boolean isAmbiguous()
return remoteNames.size() > 1;
}
}

static class DestinationTableBuilder
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the movement of this class be done in a preparatory first commit? It'll make the diff easier to understand that it's just a move and no code changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want me to make that change now? Or is it fine to go ahead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to have that since it makes it easier to make sense of history in the future.

So the move-only changes would get extracted to the first commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

TableInfo getCachedTable(ReadSessionCreatorConfig config, String query, TableInfo table)
{
try {
return destinationTableCache.get(query,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just noting that the cache key seems to be the entire query string (which can be large).
No changes requested at the moment though.

@ayushbilala ayushbilala reopened this Jun 18, 2021
@@ -13,6 +13,7 @@
*/
package io.trino.plugin.bigquery;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update commit message to Move DestinationTableBuilder to BigQueryClient

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -44,6 +44,7 @@
import java.util.Optional;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update commit message to Make BigQuery views cache ttl configurable
In general we try to follow https://chris.beams.io/posts/git-commit/ for commit messages

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member

@hashhar hashhar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address errorprone failures. LGTM otherwise.

PTAL @ebyhr.

@@ -47,6 +48,7 @@
private int maxReadRowsRetries = DEFAULT_MAX_READ_ROWS_RETRIES;
private boolean caseInsensitiveNameMatching;
private Duration caseInsensitiveNameMatchingCacheTtl = new Duration(1, MINUTES);
private Duration viewsCacheTtl = new Duration(15, TimeUnit.MINUTES);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: MINUTES is already imported at L33. Please use it instead of TimeUnit.MINUTES.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh..my bad! I'll update.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@ebyhr ebyhr merged commit e07325b into trinodb:master Jun 29, 2021
@ebyhr
Copy link
Member

ebyhr commented Jun 29, 2021

Merged, thanks!

@ebyhr ebyhr mentioned this pull request Jun 29, 2021
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

Externalise Destination Table Cache Expiry Duration for BigQuery Connector
4 participants